import cv2
import os
from PIL import Image
import numpy as np
def Laplacian(img):
    return cv2.Laplacian(img,cv2.CV_64F).var()

temp=0


from PIL import Image, ImageFilter

class MyGaussianBlur(ImageFilter.Filter):
    name = "GaussianBlur"

    def __init__(self, radius=2, bounds=None):
        self.radius = radius
        self.bounds = bounds

    def filter(self, image):
        if self.bounds:
            clips = image.crop(self.bounds).gaussian_blur(self.radius)
            image.paste(clips, self.bounds)
            return image
        else:
            return image.gaussian_blur(self.radius)

for image in os.listdir("Carplate"):
    img=Image.open("Carplate"+"/"+image)
    img = img.filter(MyGaussianBlur(radius=4))
    img=cv2.cvtColor(np.asarray(img),cv2.COLOR_BGR2RGB)
    temp+= Laplacian(img)
print(temp/len(os.listdir("Carplate")))